import java.util.Scanner;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/
public class OrderFood {
    public static void main(String[] args) {
        System.out.println("欢迎使用“吃货联盟订餐系统”");
        Scanner sc = new Scanner(System.in);
        String[] menu = {"蛋炒饭", "佛跳墙", "烤山药", "地锅鸡", "焖熊掌"};
        double[] prices = {15.0, 70.0, 10.0, 20.0, 100.0,};
        int[] praiseNums = {10, 56, 99, 55, 45};//点赞数

        //初始化6个数组用来保存订餐信息

        //用来保存订餐人信息
        String[] names = new String[5];

        //保存菜品名
        String[] megs = new String[5];

        //用来保存菜品份数
        int[] nums = new int[5];

        //保存订餐人的地址
        String[] address = new String[5];

        //保存送餐时间
        double[] times = new double[5];

        //保存订餐总额
        double[] sumPrices = new double[5];

        // 保存订单状态：0表示已预订，1表示已完成
        int[] states = new int[5];


        // 初始化2条订单信息
        // 第1条
        names[0] = "王大锤";
        menu[0] = "佛跳墙";
        times[0] = 12;
        address[0] = "莞太路3号";
        states[0] = 65;
        prices[0] = 70.0;
        // 第2条
        names[1] = "王大柱";
        menu[1] = "蛋炒饭";
        times[1] = 19;
        address[1] = "建设路2号";
        states[1] = 5;
        prices[1] = 15.0;


        int num = 1;
        boolean isExit = false;
        do {
            System.out.println("***********************************");
            System.out.println("1、我要订餐");
            System.out.println("2、查看餐袋");
            System.out.println("3、签收订单");
            System.out.println("4、删除订单");
            System.out.println("5、我要点赞");
            System.out.println("6、退出系统");
            System.out.println("***********************************");
            System.out.print("请选择：");
            int choose = sc.nextInt();


            switch (choose) {
                case 1:
                    System.out.println("***我要订餐***");
                    boolean isAdd = false;
                    for (int i = 0; i < names.length; i++) {
                        isAdd = false;
                        System.out.print("输入你的姓名：");
                        String name = sc.next();
                        System.out.println("序号" + "\t\t菜名" + "\t\t\t单价" + "\t\t\t点赞数");
                        for (int j = 0; j < menu.length; j++) {
                            System.out.println((j + 1) + "\t\t" + menu[j] + "\t\t\t\t" + prices[j] + "元" + "\t\t\t\t" + praiseNums[j]);
                        }
                        System.out.print("请输入你要点的菜的序号：");
                        int No = sc.nextInt();
                        String meg = menu[No - 1];
                        System.out.print("你想点几份：");
                        int number = sc.nextInt();
                        System.out.println("请输入你要送餐的时间（送餐时间是10点至20点间整点送餐）：");
                        int time = sc.nextInt();
                        while (time < 10 || time > 20) {
                            System.out.println("送餐时间是10点至20点间整点送餐");
                        }
                        System.out.print("请输入送餐地址：");
                        String addres = sc.next();
                        System.out.println("*****订餐成功*****");
                        System.out.println("你定的是：" + menu[No - 1] + " " + number + "份");
                        System.out.println("送餐时间是：" + time);
                        double sumPrice = prices[i] * number;
                        double sendMenoy = (sumPrice > 50) ? 0 : 5;
                        System.out.println("餐费：" + prices[No - 1] + "元，" + "送餐费" + sendMenoy + "元，" + "总计：" + (sumPrice + sendMenoy) + "元");
                        names[i] = name;
                        megs[i] = meg;
                        nums[i] = number;
                        times[i] = time;
                        address[i] = addres;
                        sumPrices[i] = sumPrice + sendMenoy;
                        break;
                    }
                    if (isAdd) {
                        System.out.println("你的餐袋已满！");
                    }
                    break;
                case 2:
                    System.out.println("***查看餐袋***");
                    System.out.println("序号\t订餐人\t餐品名称\t餐品数量\t送餐时间\t送餐地址\t总金额\t订单状态");
                    for (int i = 0; i < names.length; i++) {
                        if (names[i] == null) {
                            String state = (states[i] == 0) ? "已预定" : "已完成";
                            System.out.println((i + 1) + "\t\t" + names[i] + "\t\t" + megs[i] + "\t\t" + nums[i] + "\t\t" + times[i] + "\t\t\t" + address[i] + "\t\t" + sumPrices[i] + "\t\t" + state );
                        }
                    }
                    break;
                case 3:
                    System.out.println("***签收订单***");
                    boolean isSignFind = false;
                    System.out.print("请输入你要查看的序号：");
                    int sign = sc.nextInt();
                    for (int i = 0; i < names.length; i++) {
                        if (names[i] != null && states[i] == 0 && sign == i + 1) {
                            states[i] = 1;
                            System.out.println("订单已完成！");
                            isSignFind = true;
                        } else if (names[i] != null && states[i] == 1 && sign == i + 1) {
                            System.out.println("您选择的订单已完成签收，不能再次签收！");
                            isSignFind = true;
                        }
                    }
                    if (isSignFind) {
                        System.out.println("没有你要查看的订单号！");
                    }
                    break;
                case 4:
                    System.out.println("***删除订单***");
                    boolean isDelId = false;
                    //订餐人\t餐品名称\t餐品数量\t送餐时间\t送餐地址\t总金额\t订单状态")
                    System.out.print("输入你要删除的订单号：");
                    int del = sc.nextInt();
                    for (int i = 0; i < names.length; i++) {
                        if (names[i] == null && states[i] == 1 && del == i + 1) {
                            isDelId = true;
                            for (int j = del - 1; j < names.length - 1; j++) {
                                names[j] = names[j + 1];
                                megs[j] = megs[j + 1];
                                nums[j] = nums[j + 1];
                                times[j] = times[j + 1];
                                address[j] = address[j + 1];
                                sumPrices[j] = sumPrices[j + 1];
                                states[j] = states[j + 1];
                            }
                            names[names.length - 1] = null;
                            megs[names.length - 1] = null;
                            nums[names.length - 1] = 0;
                            times[names.length - 1] = 0;
                            address[names.length - 1] = null;
                            sumPrices[names.length - 1] = 0;
                            states[names.length - 1] = 0;
                            System.out.println("删除订单成功！");
                        } else if (names[i] == null && states[i] == 0 && del == i + 1) {
                            isDelId = true;
                            System.out.println("订单未签收，不能被删除！");
                            break;
                        }
                    }
                    if (isDelId) {
                        System.out.println("您要删除的订单不存在！");
                    }
                    break;
                case 5:
                    System.out.println("***我要点赞***");
                    break;
                case 6:
                    System.out.println("***退出系统***");
                    break;
                default:
                    isExit = true;
                    break;
            }
            if (!isExit) {
                System.out.println("输入0返回：");
                num = sc.nextInt();
            } else {
                break;
            }
        } while (num == 0);


    }
}
